package cn.sunshine.basic.controller;

import cn.sunshine.basic.annotation.PreAuthorize;
import cn.sunshine.basic.dto.RegisterDto;
import cn.sunshine.basic.exception.BusinessException;
import cn.sunshine.basic.utils.AjaxResult;
import cn.sunshine.basic.service.IVerifyCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {
    @Autowired
    public IVerifyCodeService verifyCodeService;

    /*
    * @Title: get
    * @Description: 获取图形验证。
    * @Author: Mr.Jiang
    * @Version: 1.0
    * @Date:  2022/7/4 21:41
    * @Parameters: [key]
    * @Return cn.sunshine.org.domain.ShopAuditLog
    */
    @GetMapping("/image/{key}")
    public AjaxResult grap(@PathVariable String key) {
        try {//
            String base64Str = verifyCodeService.grap(key);
            System.out.println(base64Str);
            return AjaxResult.getAjaxResult().setResultObj(base64Str);
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.getAjaxResult().setSuccess(false).setMessage("系统繁忙，请重试");
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.getAjaxResult().setSuccess(false).setMessage("系统繁忙，请重试");
        }

    }
/*
* @Title: smsCode
* @Description: 调用业务层发送短信验证码
* @Author: Mr.Jiang
* @Version: 1.0
* @Date:  2022/7/13 19:17
* @Parameters: [registerDto]
* @Return cn.sunshine.basic.utils.AjaxResult
*/
    @PostMapping("/smsCode")

    public AjaxResult smsCode(@RequestBody RegisterDto registerDto) {
        try {// 调用业务层发送短信验证码


            verifyCodeService.smsCode(registerDto);


            return AjaxResult.getAjaxResult();
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.getAjaxResult().setSuccess(false).setMessage("系统繁忙，请重试");
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.getAjaxResult().setSuccess(false).setMessage("系统繁忙，请重试");
        }

    }
}





